package com.bugman.managed;

import com.bugman.entity.Role;
import com.bugman.entity.User;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.model.SelectItem;

/**
 *
 * @author ediczech
 */
public class PromoteUsersBean extends BaseBean {

    private List<User> developers = new ArrayList<User>();
    private List<String> developerIds = new ArrayList<String>();
    private List<SelectItem> users = new ArrayList<SelectItem>();

    @PostConstruct
    public void init() {
        // create List of selectItems
        for (User user : userService.getUsers(Role.USER)) {
            users.add(new SelectItem(user.getId().toString(), user.getNick()));
        }
    }

    public String promote() {
        List<Integer> ids = new ArrayList<Integer>();
        for (String id : developerIds) {
            ids.add(Integer.valueOf(id));
        }
        developers = userService.getUsers(ids);
        userService.setDevelopers(developers);
        return "success";
    }

    public List<String> getDeveloperIds() {
        return developerIds;
    }

    public void setDeveloperIds(List<String> developerIds) {
        this.developerIds = developerIds;
    }

    public List<User> getDevelopers() {
        return developers;
    }

    public void setDevelopers(List<User> developers) {
        this.developers = developers;
    }

    public List<SelectItem> getUsers() {
        return users;
    }

    public void setUsers(List<SelectItem> users) {
        this.users = users;
    }

    
}
